from datetime import datetime

from django.shortcuts import render
from django.http import HttpResponse
from django.template.loader import get_template

from .models import Post
# Create your settingviews here.


def index(request):
    return HttpResponse("这是计划管理的系统设置管理器.....")


def add(request, a, b):
    # c = int(a) + int(b)
    c = str(a) + str(b)
    return HttpResponse(int(c))

def postList(request):
    posts = Post.objects.all()
    post_list = list()
    for count, post in enumerate(posts):
        post_list.append("No.{}".format(str(count)) + str(post) + "<br>")
        post_list.append("<small>" + str(post.body) + "</small><br><br>")
    return HttpResponse(post_list)

def settingIndex(request):
    template = get_template("setting/index.html");
    posts = Post.objects.all();
    now = datetime.now()
    html = template.render(locals())
    return HttpResponse(html)

def post_href(request):
    posts = Post.objects.all();
    return render(request, 'setting/post_href.html', {'posts': posts, 'now': datetime.now()})

def post_id(request, id):
    post = Post.objects.get(id=id)
    if post != None:
        return render(request, 'setting/post_id.html', {"post": post, "now": datetime.now()})






